Mastering Rust by Rahul Sharma
Author:Rahul Sharma
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2019-01-31T20:10:52+00:00
println!("Bytestring says {}", string_from_bytestring);
empty_string.push('1');
println!("1) Empty string now contains {}", empty_string);
empty_string.push_str("2345");
println!("2) Empty string now contains {}", empty_string);
println!("Length of the previously empty string is now {}",
empty_string.len());
}
With String explored, let's look at the borrowed version of strings known as string slices or the &str type.
Borrowed strings – &str
We can also have strings as references called string slices. These are denoted by &str (pronounced as stir), which is a reference to a str type. In constrast to the String type, str is a built-in type known to the compiler and is not something from the standard library. String slices are created as &str by default—a pointer to a UTF-8 encoded byte sequence. We cannot create and use values of the bare str type, as it represents a contiguous sequence of UTF-8 encoded bytes with a finite but unknown size. They are technically called unsized types. We'll explain unsized types later in this chapter.
str can only be created as a reference type. Let's assume we try to create a str type forcibly by providing the type signature on the left:
// str_type.rs
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25294)
Hello! Python by Anthony Briggs(24339)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23434)
Kotlin in Action by Dmitry Jemerov(22512)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21976)
Dependency Injection in .NET by Mark Seemann(21848)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20715)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19523)
Grails in Action by Glen Smith Peter Ledbrook(18609)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17034)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15843)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13691)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11857)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11151)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10624)
Hit Refresh by Satya Nadella(9202)
The Kubernetes Operator Framework Book by Michael Dame(8570)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8408)
Robo-Advisor with Python by Aki Ranin(8361)